package com.sykj.springboot.controller;

import com.sykj.springboot.common.entity.JsonResult;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.sykj.springboot.syslog.CustomLog;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@RestController
@RequestMapping("hello")
public class HomeController {

	@Value("${com.sykj.name}")
	private String name;


	@RequestMapping("sayHello")
	@CustomLog(action = "用户操作", description = "添加用户")
	public JsonResult sayHello() {
		System.out.println(name);
        JsonResult result = new JsonResult("hello",JsonResult.TIME_OUT);
        result.setData("hello");
		return result;
	}


    @RequestMapping("sayHi")
    @ResponseBody
    public String sayHi() {
        System.out.println(name);
        return "hi";
    }

    @ResponseBody
    @RequestMapping("redirctSayHi")
    public String redirctSayHi(HttpServletResponse response) {
        System.out.println(name);
        try {
            response.sendRedirect("/index");
            return "";
        } catch (IOException e) {
        }
        return "forword:/index";
    }
}
